package com.common.util;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.FastDateFormat;

/**
 * @author ficus 日期解析工具
 */
public final class DateParseUtil {

	private static String[] parsePatterns = { 
			"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
			"yyyy-MM-dd HH:mm:ss",
			"yyyy-MM-dd",  
			"yyyy-MM-dd HH:mm", 
			"yyyy-MM",
			"yyyy/MM/dd", 
			"yyyy/MM/dd HH:mm:ss", 
			"yyyy/MM/dd HH:mm", 
			"yyyy/MM", 
			"yyyy.MM.dd", 
			"yyyy.MM.dd HH:mm:ss",
	        "yyyy.MM.dd HH:mm", 
	        "yyyy.MM", 
	        "yyyyMMddHHmmss",
	        "yyyy-MM-dd'T'HH:mm:ss.SSS",
			"yyyy-MM-dd'T'HH:mm:ss.ss'ZZ'",
			"yyyy-MM-dd'T'HH:mm:ss.SSS'ZZ'"
    };
	
    public static Date parseDate(String dateString,String pattern) throws ParseException {
        return FastDateFormat.getInstance(pattern).parse(dateString);
    }
    
    public static Date parseDate(final String str, final String... parsePatterns) throws ParseException {
        return DateUtils.parseDate(str, parsePatterns);
    }
    
    public static Date parseDate(String dateString) throws ParseException {
    	return DateUtils.parseDate(dateString, parsePatterns);
    }
}
